<template>
    <div class="Clist" ref="dom">
      <div>
        <div class="Clist-title border-topbottom">当前城市</div>
        <div class="Clist-button">
            <div class="Clist-button-text">
                <div class="Clist-button-t">{{this.city}}</div>
            </div>
        </div>
        <div class="Clist-title border-topbottom">热门城市</div>
        <div class="Clist-button">
            <div class="Clist-button-r">
                <div class="Clist-button-text" v-for="item of hotcitys" :key="item.id" @click='handClick(item.name)'>
                    <div class="Clist-button-t">{{item.name}}</div>
                </div>
            </div>
        </div>
          <div v-for="(item,key) of citys" :key="key" :ref="key">
            <div class="Clist-title border-topbottom">{{key}}</div>
            <div class="Clist-list" v-for="item1 of item" :key="item1.id"  @click='handClick(item1.name)'>
            <div class="Clist-item border-bottom">{{item1.name}}</div>
            </div>
        </div>
      </div>
    </div>
</template>

<script>
import Bscroll from 'better-scroll'
import { mapState, mapMutations } from 'vuex'
export default {
  name: 'Clist',
  props: {
    citys: Object,
    hotcitys: Array,
    msg1: String
  },
  mounted () {
    this.scroll = new Bscroll(this.$refs.dom, { mouseWheel: true, click: true, tap: true })
  },
  methods: {
    handClick (city) {
      this.change(city)
      this.$router.push('/')
    },
    ...mapMutations(['change'])
  },
  computed: {
    ...mapState(['city'])
  },
  watch: {
    msg1 () {
      if (this.msg1) {
        const elment = this.$refs[this.msg1][0]
        this.scroll.scrollToElement(elment)
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
    .border-bottom
        &:before
            border-color: #cccccc
    .border-topbottom
        &:before
            border-color: #ccc
        &:after
            border-color: #ccc
    .Clist
        position: absolute
        overflow: hidden
        top: 1.58rem
        bottom: 0
        left: 0
        right: 0
        .Clist-title
            line-height: .54rem
            background: #eeeeee
            padding-left: .2rem
            color: #666
        .Clist-button
            overflow: hidden
            padding-right: .6rem
            box-sizing: border-box
            .Clist-button-text
                float: left
                width: 33.3%
                box-sizing: border-box
                padding: .2rem
                height: 1.2rem
                .Clist-button-t
                    width: 100%
                    height: 100%
                    text-align: center
                    line-height: .5rem
                    box-sizing: border-box
                    padding: .1rem
                    border: .05rem solid #cccccc
        .Clist-list
            .Clist-item
                line-height: .76rem
                padding-left: .2rem
</style>
